﻿<!DOCTYPE html>
<!--试题管理列表-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <style>
        .el-table_1_column_3 {
            text-align: left !important;
        }
    </style>

</head>

<body>
    <div id="app" v-cloak class="popupW50">
        <el-row>
            <el-col :span="24">
                <el-form ref="form" :inline="true" label-position="right" label-width="100px"
                         :model="formInline" class="demo-form-inline" style="margin-bottom: 15px;">
                    <el-col class="head-tool">

                        <div class="new_title fl"><strong><img src="/static/images/icon1.png" />课程类别列表</strong></div>
                        <span>
                            <btn :text="col.btnSelect" imgsrc="/static/images/search.png" linetype="3"
                                 @click="onSubmit">
                            </btn>
                            <btn :text="col.btnAdd" linetype="3" @click="UserInput('tj')"></btn>

                            <!--<btn :text="col.btnExcelTemplate" imgsrc="/static/images/general.png" linetype="3"
                 @click="btnExcelTemplate"></btn>-->
                            <btn :text="col.btnDelete" linetype="4" @click="onDelete"></btn>
                        </span>
                    </el-col>
                    <list-factorys v-model="formInline.model.createFactory" @change="factoryChange"></list-factorys>
                    <el-col :xs="8" :sm="8" :md="8" :lg="6" :xl="6">
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input v-model="formInline.model.Name"
                                          :placeholder="'课程类别名称'" size="mini">
                                    <template slot="prepend">
                                        {{'课程类别名称'+mark.m}}
                                    </template>
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-form>
            </el-col>

            <el-col :span="24">
                <el-table class="ele_expand"  ref="table" stripe :data="ListItem.tableData" :height="ListItem.tableHeight" border
                          @selection-change="handleSelectionChange" row-style="height:10px"
                          row-key="id"
                          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                          style="width: 100%">
                    <el-table-column type="selection" align="center" width="55">
                    </el-table-column>
                    <el-table-column type="index" :label="col.SequenceNumber" :index="indexMethod" width="50">
                    </el-table-column>
                    <!-- <el-table-column type="index" :label="QuestionManagement.SerialNumber" :index="indexMethod" width="50"
                        show-overflow-tooltip="true"></el-table-column> -->
                    <el-table-column prop="name"
                                     :label="'课程类别名称'"
                                     show-overflow-tooltip="true"
                                     min-width="400">
                    </el-table-column>

                    <el-table-column width="53" prop="update" :label="col.btnUpdate" fixed="right">
                        <template slot-scope="scope">
                            <button type="button" class="elst-bt-xg" @click=UserInput('xg',scope.row.id)>
                                <i class="el-icon-edit"></i>
                            </button>
                        </template>
                    </el-table-column>
                </el-table>
                <!--<el-row type="flex" justify="end">
                    <el-pagination ref="page" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :current-page="ListItem.currentPage" :page-sizes="ListItem.pagesizes"
                                   :page-size="ListItem.pagesize" :layout="ListItem.layout" :total="ListItem.total">
                    </el-pagination>

                </el-row>-->
            </el-col>
        </el-row>
        <el-dialog title="课程类别管理" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%" top="10vh" fullscreen="true">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">

        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    show: false,
                    TreeData: [],
                    mydata: QuestionManagementTree,
                    defaultProps: {
                        children: 'children',
                        label: 'label'
                    },
                    RiskLevel: [],
                    ListItem: ListItem,
                    formInline: {
                        model: {
                            Name: '',//名称
                            Code: '',//编码
                            CreateFactory: null,//隶属工厂

                        },
                        offset: 0,
                        limit: 10
                    }
                }
            }, created: function () {
                var currApp = this;
                window.onresize = function () {
                    currApp.ListItem.tableHeight = window.innerHeight -
                        currApp.$refs.table.$el.offsetTop - 60;
                    if (currApp.ListItem.tableHeight < 112) {
                        currApp.ListItem.tableHeight = 112;
                    }
                }
            },
            mounted: function () {
                //初始化数据
                this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);
                this.TreeData = fn(this.mydata, "0");
            },
            methods: {
                factoryChange: function () {
                   
                    this.GetPageData(1);

                },
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                btnExcelTemplate: function () {
                    this.$message({
                        message: '模版导出成功！',
                        type: 'success'
                    });
                },
                indexMethod: function (index) {
                    return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1;
                },

                handleNodeClick: function (data) {
                    if (!data.children) {
                        this.formInline.model.TreeNode = data.id
                        onSubmit(this);
                    } else {
                        if (data.icon == "tree-open") {
                            data.icon = "tree-close"
                        } else (
                            data.icon = "tree-open"
                        )
                    }
                },
                closeDialog: function () { closeDialog(this); },
                //删除方法
                onDelete: function () {
                    var mythis = this;

                    if (mythis.ListItem.tableMultipleSelection.length == 0) {
                        showMessage(msg.AtLeastOne, 'error')
                        return;
                    }
                    mythis.$confirm(' 是否确认继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        var delIds = [];
                        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
                            var item = mythis.ListItem.tableMultipleSelection[i];
                            delIds.push(item.id);
                        }
                        myAjax("post", mythis, '/api/PX_CourseClass/DeleteMuti', delIds, function (response) {
                            mythis.GetPageData();
                            mythis.onTable();
                            showMessage(msg.OperatingOk, "success");
                        });
                    }).catch(function () {
                        showMessage("已取消删除!");
                    });
                    //onDelete(this, '/api/PX_CourseClass/DeleteMuti');
                },





                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //Dialog展示
                UserInput: function (val, id) { DialogShow(this, val, "CourseClassInput.html", id); },
                //获取分页数据
                GetPageData: function (type) {

                    var mythis = this;
                    myAjax("post", this, '/api/PX_CourseClass/GetList', mythis.formInline, function (response) {
                        mythis.ListItem.dataSource = response.data.pageData;
                    }, false);

                    //筛选后容器
                    var list = [];
                    //数据源
                    var dataSource = mythis.ListItem.dataSource;
                    //筛选条件
                    var Name = mythis.formInline.model.Name;
                   
                    //过滤填充
                    for (var i = 0; i < dataSource.length; i++) {
                        var v = dataSource[i];

                        if (Name && v.name.indexOf(Name) == -1)
                            continue;

                        list.push(v);

                    }

                    if (type) {
                        if (list.length > 0) {
                            list.forEach(function (v, i) {
                                //获取父级
                                getParentNodes(v, dataSource, list);
                            })
                        }
                        //去重
                        list = uniq(list)
                    }
                    //扁平分级

                    list = menuHelper(list, guidEmpty);

                    //绑定页面表格
                    mythis.ListItem.tableData = list;

                    //GetPageData(this, currentIndex, '/api/PX_CourseClass/GetList')
                },
                //查询方法
                onSubmit: function () {

                    this.GetPageData(true);
                    this.onTable();
                },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
                onTable: function () {
                    //获取所有行，并去掉display:none 蠢办法，将就用
                    var els = this.$el.getElementsByClassName('el-table__row')
                    for (var i = 0; i < els.length; i++) {
                        if (els[i].style.display) {
                            els[i].style.display = "";
                        }
                    }
                },
            }
        });

        //步骤1：递归父级
        function getParentNodes(obj, data, result) {
            console.log('obj', obj)
            if (obj.pId != guidEmpty && obj.pId) {
                data.forEach(function (v, i) {
                    if (obj.pId == v.id) {
                        result.push(v);
                        getParentNodes(v, data, result);
                    }
                })
            }
        }
        //步骤2：去重数据
        function uniq(array) {
            var temp = [];
            for (var i = 0; i < array.length; i++) {
                //如果当前数组的第i项在当前数组中第一次出现的位置是i，才存入数组；否则代表是重复的
                if (array.indexOf(array[i]) == i) {
                    temp.push(array[i])
                }
            }
            return temp;
        }
        //步骤3：数据序列化(tabletree)
        function menuHelper(list, pid) {

            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }

                temp.pId = temp.pId ? temp.pId : guidEmpty;
                var obj;
                if (temp.pId == pid) {
                    obj = temp;
                    var nextObj = menuHelper(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
        //data:字典数据集，key:键
        function getDicValue(data, key) {
            var val = key;
            if (data.length > 0) {
                data.forEach(function (o, j) {
                    if (o.key == key) {
                        val = o.value;
                        return;
                    }
                });
            }
            return val;
        }

    </script>
</body>

</html>